<template>
  <div>
    <h1>转发</h1>
    <el-button type="primary" @click="openAdd">转发文章</el-button>
    <el-table
      :data="specialist"
      style="width: 100%">
      <el-table-column
        prop="transmitId"
        label="transmitId"
        width="180">
      </el-table-column>
      <el-table-column
        prop="userId"
        label="转法人id"
        width="180">
      </el-table-column>
      <el-table-column
        prop="fileId"
        label="转发文章id"
        width="180">
      </el-table-column>
      <el-table-column
        prop="transmitTitle"
        label="标题"
        width="180">
      </el-table-column>
      <el-table-column
        label="操作"
        width="260">
        <template slot-scope="scope" >
          <el-button type="primary" @click="deltransmit(scope.row.transmitId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      title="添加/修改文章"
      :visible.sync="dialogVisible"
      width="60%">
      <el-form ref="form" :model="expert" label-width="80px">
        <el-form-item label="转发人">
          <el-input v-model="expert.userId"></el-input>
        </el-form-item>
        <el-form-item label="转发文章id">
          <el-input v-model="expert.fileId"></el-input>
        </el-form-item>
        <el-form-item label="转发标题">
          <el-input v-model="expert.transmitTitle"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addtransmit">立即创建</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <div class="block">
      <el-pagination
        :current-page="file.pagenum"
        :page-sizes="[2,3,1]"
        :page-size="file.pagenum"
        layout="total, sizes, prev, pager, next, jumper"
        :total="file.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange">
      </el-pagination>
    </div>

  </div>
</template>
<script>
  import {findtransmit,deltransmit,addtransmit} from '@/api/bbs'
  export default {
    data(){
      return{
        specialist:[],
        dialogVisible:false,
        expert:{},
        file: {
          pagenum :1,
          pagesize :3,
          total :0
        }
      }
    },
    mounted(){
      this.findtransmit();
    },
    methods: {
      addtransmit(){
        addtransmit(this.expert).then(res=>{
          alert(res.msg)
          this.expert={}
          this.dialogVisible=false
          this.findtransmit()
        })
      },
      findtransmit(){
        findtransmit(this.file).then(res=>{
          console.log(res.data)
          this.specialist=res.data;
          this.file.total=res.total;
        })
      },
      deltransmit(transmitId){
        deltransmit(transmitId).then(res=>{
          alert(res.msg),
          location.reload();
        })
      },
      openAdd(){
        this.dialogVisible=true
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
      }
    }
  }
</script>
<style>

</style>
